<template>
  <div
    v-show="modal">
    <div class="returnBtn">
      <t-button icon="arrow-left" @click="cancel">取消</t-button>
    </div>
    <div class="content">
      <t-form ref="menu" :model="formValidate" :rules="ruleValidate" :label-width="80">
        <div class="row">
          <div class="col-6 p-r-15">
            <t-form-item label="菜单名称" prop="name">
              <t-input v-model="formValidate.name" placeholder="请输入..."></t-input>
            </t-form-item>
          </div>
          <div class="col-6 p-l-15">
            <t-form-item label="菜单排序" prop="sort">
              <t-input v-model="formValidate.sort" placeholder="请输入..."></t-input>
            </t-form-item>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <t-form-item label="菜单地址" prop="address">
              <t-input v-model="formValidate.address" placeholder="请输入..."></t-input>
            </t-form-item>
          </div>
        </div>
        <div class="row">
          <div class="col-6 p-r-15">
            <t-form-item label="菜单图标">
              <t-input v-model="formValidate.icon" placeholder="请输入..."></t-input>
            </t-form-item>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <t-form-item label="备注">
              <t-input v-model="formValidate.remarks" :rows="10" spellcheck = "false" type="textarea" placeholder="请输入"></t-input>
            </t-form-item>
          </div>
        </div>
      </t-form>
      <div class="btns">
        <div>
          <t-button @click="cancel">取消</t-button><t-button type="primary" style="margin-left:14px" @click="preservation">保存</t-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import http from '../../../http'
import services from '../../../conf/services'
export default {
  props: {
    addShowFlg: Boolean,
    editFlg: Boolean,
    datas: Object,
    // 修改页面带过来的数据
    editDatas: Object
  },
  data () {
    return {
      title: '',
      modal: false,
      formValidate: {
        name: '',
        address: '',
        remarks: '',
        icon: '',
        sort: ''
      },
      ruleValidate: {
        sort: [
          {required: true, message: '菜单排序不能为空', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '菜单名称不能为空', trigger: 'blur'}
        ],
        address: [
          {required: true, message: '菜单地址不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  watch: {
    // 添加页面过来的开关
    addShowFlg (curVal, oldVal) {
      this.title = '新建菜单'
      this.modal = true
      this.onReset()
    },
    // 修改页面过来的开关
    editFlg (curVal, oldVal) {
      this.title = '编辑菜单'
      this.modal = true
      this.onReset()
    }
  },
  methods: {
    // 获取数据
    getCeptList(ids) {
      http.$seb
        .post(services.seb.GET_CEPLIST_FINDBYID, {
          request: {
            id: ids
          },
          needPagination: true,
          pageNum: 0,
          pageSize: 0
        })
        .then(res => {
          if (res.data.resultCode === '0') {
            this.formValidate.name = res.data.result.name
            this.formValidate.address = res.data.result.address
            // this.cepStatelList
            // this.dataList = res.data.result.response
            // this.pageTotal = res.data.result.totalCount
          }
        }).catch(v => {
          console.log(v)
        })
    },
    // 表单重置
    onReset() {
      this.$refs['menu'].resetFields()
    },
    // 保存
    preservation () {
      this.$refs['menu'].validate(valid => {
        if (valid) {
          /* bo: 'pm',
        bC: 'PM_SYSTEM_DICTIONARY',
        ins_value: JSON.stringify({
          'CODE': 'BU',
          'STATUS': '1'
        }),
        begin: 0,
        row: 0 */
          this.modal = false
          let list = {}
          let datas = {}
          list.bo = 'user'
          list.bc = 'USER_FUNCTION'
          datas.FUNC_TYPE = 'H'
          datas.MODULE_CODE = '0356'
          datas.NAME = this.formValidate.name
          datas.VIEWNAME = this.formValidate.address
          datas.FUN_SEQ = this.formValidate.sort
          datas.FUNC_IMG = this.formValidate.icon
          datas.REMARK = this.formValidate.remarks
          list.ins_value = JSON.stringify(datas)
          if (this.title === '新建菜单') {
            console.log(http)
            http.$http.post(services.USERMNG_CREATE, list)
              .then(res => {
                console.log(res)
                if (res.data.resultCode === '0') {
                  this.$Message.success('新建工作流模板成功!')
                  this.$emit('refresh')
                } else {
                  // 删掉上面赋值的1
                  // this.formValidate.inputText = ''
                  // console.log(1)
                  // this.modal = true
                  this.$Message.danger('新建CEP失败!')
                }
              })
          } else if (this.title === '编辑菜单') {
            // datas.request.id =
            http.$seb
              .post(services.seb.UPDATE_CEP, datas)
              .then(res => {
                if (res.data.resultCode === '0') {
                  this.$Message.success('修改工作流模板成功!')
                  this.$emit('refresh')
                } else {
                  this.$Message.danger('修改工作流模板失败!')
                }
              })
          }
        } else {
          if (this.title === '新建菜单') {
            this.modal = true
            this.$Message.danger('新建菜单失败!')
          } else if (this.title === '编辑菜单') {
            this.modal = true
            this.$Message.danger('编辑菜单失败!')
          }
        }
      })
    },
    reset () {
      this.formValidate.name = ''
      this.formValidate.address = ''
      this.formValidate.remarks = ''
      this.formValidate.icon = ''
      this.formValidate.sort = ''
    },
    cancel () {
      console.log(222222)
      this.$emit('refresh')
      this.modal = false
      this.onReset()
      // this.$Message.info('点击了取消')
    }
  }
}
</script>
<style scoped lang="less">
.returnBtn{
  margin-left: 30px;
  margin-top: 30px;
}
.content{
  max-width: 590px;
  margin: 0 auto 128px;
  .col-6,
  .col-12{
    padding: 0;
  }
  .p-r-15{
    padding-right: 15px;
  }
  .p-l-15{
    padding-left: 15px;
  }
  .btns{
    // display: inline-block;
    max-width: 170px;
    margin: 0 auto;
  }
}
.type{
  position: relative;
  span {
    position: absolute;
    left: 82px;
    top: -27px;
    padding-left: 5px;
    color: red;
  }
  .feedback{
    .icon{
      display: inline-block;
      width: 12px;
      height: 12px;
      color: red;
      font-size: 12px;
      margin-right: .3em;
    }
  }
}
</style>
